package com.zang.stackqueue;

import java.util.Stack;

/**
 * 有效的括号
 * @author ZVerify
 * @since 2022/10/18 22:00
 * @see <a href="https://leetcode.cn/problems/valid-parentheses/">...</a>
 **/
public class 有效的括号 {

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        for(char c: s.toCharArray()){
            if(c=='(')stack.push(')');
            else if(c=='[')stack.push(']');
            else if(c=='{')stack.push('}');
            else if(stack.isEmpty()||c!=stack.pop())return false;
        }
        return stack.isEmpty();
    }
}
